package com.leetcode.week.week291;

/**
 * @author angzhijin
 * @Description
 * @create 2022-05-01 10:32 上午
 */
public class LeetCodeWeek1 {
    public static void main(String[] args) {
        String s = removeDigit("11", '1');
        System.out.println(s);

    }

    public static String removeDigit(String number, char digit) {
        int length = number.length();
        String res = "";
        StringBuffer sb;
        for(int i=0; i<number.length(); i++){
//            System.out.println(res);
            sb = new StringBuffer(number);
            if(sb.charAt(i) == digit){
                sb.deleteCharAt(i);
                if(res.equals("")){
                    res = sb.toString();
                    System.out.println(res);
                    continue;
                }
                int j=0;
                while (j<length-1){
                    if(sb.charAt(j)>res.charAt(j)){
                        res = sb.toString();
                        break;
                    }else if(sb.charAt(j)<res.charAt(j)){
                        break;
                    }
                    j++;
                }
//                //铁憨憨，明明可以更简单
//                String str = number.substring(0,i)+number.substring(i+1);
//                if (str.compareTo(res) > 0){
//                    res = str;
//                }
            }
            //System.out.println(res);
            sb = new StringBuffer(number);
        }
        return res;
    }
}
